
#include "TwoD_TexCan.h"


/////////////////////////////////////
////          Struct part        ////
/////////////////////////////////////


TwoD_TexCan_Conf::TwoD_TexCan_Conf() : Data_Base_Conf(),  Can_Array_Conf<TYPE_TEXARR>()
{
    m_cAssetAdapter = new Asset_Adapter();
    m_cAssetAdapter->appSet(Static_APP::s_sApp);
}



/////////////////////////////////////
////          Class part         ////
/////////////////////////////////////


/**
 *
 */
TwoD_TexCan* TwoD_TexCan::findByIdentifier(int* a_arIdent, int a_nSize)
{
    int _argIdentSize = 0;
    if(a_nSize <= 0)
    {
        _argIdentSize = sizeof(*a_arIdent) / sizeof(int);
    }
    else
    {
        _argIdentSize = a_nSize;
    }
    
    // new a instance to store the new list
    //TYPE_TEXARR** _result = (TYPE_TEXARR**)malloc(sizeof(TYPE_TEXARR*) * _argIdentSize);
    
    TwoD_TexCan* _result = new TwoD_TexCan();
    
    LOGI("find in for begin: _argIdentSize %d arrSize: %d\n", _argIdentSize, this->m_sTwoD_TexCan_Conf->size);

    int k = 0;
    for(k = 0; k < _argIdentSize; k++)
    {
        int i = 0;
        for(i = 0; i < this->m_sCan_Array_Conf->size; i++)
        {
            if(m_arData[i] != NULL || m_arData[i]->identifier == a_arIdent[k])
            {
                LOGI("ident: %d arg: %d\n", this->m_arData[i]->identifier, a_arIdent[k]);
                _result->putOne(m_arData[i]);
                break;
            }
        }
    }
    
    return _result;
}

/**
 *
 */
TwoD_TexCan::TwoD_TexCan() : Data_Base(), Can_Array<TYPE_TEXARR>()
{
    m_sTwoD_TexCan_Conf = new TwoD_TexCan_Conf();
    // init list
    this->m_arData = (TYPE_TEXARR**)malloc(sizeof(TYPE_TEXARR*) * this->m_sCan_Array_Conf->size);
}

/**
 *
 */
int TwoD_TexCan::loadTex()
{
    // open asset
    AAsset* _asset = this->m_sTwoD_TexCan_Conf->m_cAssetAdapter->assOpen("rol1008.bmp", AASSET_MODE_UNKNOWN);
    this->m_sTwoD_TexCan_Conf->m_cAssetAdapter->assSeek(_asset, 70, SEEK_SET);
    
    // new a texdataset for store buffer data
    TYPE_TEXARR* _tex =  new TwoD_TexBean();
    off_t _bufferSize = AAsset_getLength(_asset);
    _tex->m_vData = (GLbyte*)malloc(_bufferSize);
    _tex->identifier = 107;
    //
    int _size = AAsset_read(_asset, _tex->m_vData, _bufferSize);
    // put int array
    //this->m_arData[0] = _tex;
    this->putOne(_tex);
}








